package com.healthcarex.hip.saas.security.service.impl;

import com.healthcarex.hip.saas.security.dao.DeptDao;
import com.healthcarex.hip.saas.security.model.SysDept;
import com.healthcarex.hip.saas.security.service.IDeptService;
import com.healthcarex.hip.saas.security.util.SecurityUtils;
import com.healthcarex.hip.saas.mybatis.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;

/**
 * @author chenpan
 * @ClassName: DeptServiceImpl
 * description:
 * @date 2018-04-09 10:28
 */
@Service
public class DeptServiceImpl extends BaseServiceImpl<SysDept> implements IDeptService {

    @Autowired
    private DeptDao deptDao;

    @Override
    public void updateDeptOrg(SysDept dept) {

        Example example = new Example(SysDept.class);
        example.createCriteria().andCondition("org_code=", dept.getDeptCode());

        SysDept newDept = new SysDept();
        newDept.setOrgCode(dept.getOrgCode());
        newDept.setOrgName(dept.getOrgName());
        newDept.setUpdateBy(SecurityUtils.getUsername());
        newDept.setUpdateTime(new Date());
        newDept.setUpdateCount(dept.getUpdateCount() == null ? 0 : dept.getUpdateCount() + 1);
        deptDao.updateByExampleSelective(newDept, example);
    }
}
